//------------------------------------------------------------------------------
//此代码由工具生成
//请使用partial类进行扩展,避免修改被覆盖
//------------------------------------------------------------------------------
using System;
using System.Text;
using System.Collections.Generic;
namespace XKPlatform.DataModels
{
    public partial class SysProjectDao
    {
        public static List<SysProjectModel> GetSysProjectModelList(int pageIndex,int pageSize,string whereSql,Dictionary<string,object> paramMap, string orderByField,int orderByType,out int totalCount)
        {
            var list = new List<SysProjectModel>();
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysProject where 1 = 1 " + whereSql;
                if (orderByType == 1)
                {
                    sql += string.Format(" Order by {0} asc Offset {1} Row Fetch Next {2} Rows Only; ", orderByField, (pageIndex - 1) * pageSize, pageSize);
                }
                else
                {
                    sql += string.Format(" Order by {0} desc Offset {1} Row Fetch Next {2} Rows Only; ", orderByField, (pageIndex - 1) * pageSize, pageSize);
                }
                conn.ExecuteReader(sql, paramMap, (rdr) =>
                {
                    var item = new SysProjectModel();
                    item.ID = rdr["ID"].ObjectToInt(0);
                    item.No = rdr["No"].ToString();
                    item.ProjectNo = rdr["ProjectNo"].ToString();
                    item.ProjectName = rdr["ProjectName"].ToString();
                    item.CreatedBy = rdr["CreatedBy"].ToString();
                    item.CreatedOn = rdr["CreatedOn"].ObjectToDateTime();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ObjectToDateTime();
                    item.RecordStatus = rdr["RecordStatus"].ObjectToBoolean(false);
                    item.ImportBatch = rdr["ImportBatch"].ObjectToInt(0);
                    item.proUrl = rdr["proUrl"].ToString();
                    item.HomePage = rdr["HomePage"].ToString();
                    list.Add(item);
                });
                sql = "select count(1) from SysProject where 1 = 1 " + whereSql;
                totalCount = (int)conn.ExecuteScalar(sql, paramMap);
                return list;
            }
        }
        public static List<SysProjectModel> GetSysProjectModelList(string whereSql,Dictionary<string,object> paramMap)
        {
            var list = new List<SysProjectModel>();
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysProject where 1 = 1 " + whereSql;
                conn.ExecuteReader(sql, paramMap, (rdr) =>
                {
                    var item = new SysProjectModel();
                    item.ID = rdr["ID"].ObjectToInt(0);
                    item.No = rdr["No"].ToString();
                    item.ProjectNo = rdr["ProjectNo"].ToString();
                    item.ProjectName = rdr["ProjectName"].ToString();
                    item.CreatedBy = rdr["CreatedBy"].ToString();
                    item.CreatedOn = rdr["CreatedOn"].ObjectToDateTime();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ObjectToDateTime();
                    item.RecordStatus = rdr["RecordStatus"].ObjectToBoolean(false);
                    item.ImportBatch = rdr["ImportBatch"].ObjectToInt(0);
                    item.proUrl = rdr["proUrl"].ToString();
                    item.HomePage = rdr["HomePage"].ToString();
                    list.Add(item);
                });
                return list;
            }
        }
        public static List<SysProjectModel> GetSysProjectModelList()
        {
            var list = new List<SysProjectModel>();
            using (var conn = DbHelper.OpenConn())
            {
                conn.ExecuteReader("select * from SysProject", null,(rdr)=>
                {
                    var item = new SysProjectModel();
                    item.ID = rdr["ID"].ObjectToInt(0);
                    item.No = rdr["No"].ToString();
                    item.ProjectNo = rdr["ProjectNo"].ToString();
                    item.ProjectName = rdr["ProjectName"].ToString();
                    item.CreatedBy = rdr["CreatedBy"].ToString();
                    item.CreatedOn = rdr["CreatedOn"].ObjectToDateTime();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ObjectToDateTime();
                    item.RecordStatus = rdr["RecordStatus"].ObjectToBoolean(false);
                    item.ImportBatch = rdr["ImportBatch"].ObjectToInt(0);
                    item.proUrl = rdr["proUrl"].ToString();
                    item.HomePage = rdr["HomePage"].ToString();
                    list.Add(item);
                });
                return list;
            }
        }
        public static SysProjectModel GetSingleSysProjectModel(string whereSql,Dictionary<string,object> paramMap)
        {
            SysProjectModel item = null;
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysProject where 1 = 1 " + whereSql;
                conn.ExecuteReader(sql, paramMap,(rdr)=>
                {
                    item = new SysProjectModel();
                    item.ID = rdr["ID"].ObjectToInt(0);
                    item.No = rdr["No"].ToString();
                    item.ProjectNo = rdr["ProjectNo"].ToString();
                    item.ProjectName = rdr["ProjectName"].ToString();
                    item.CreatedBy = rdr["CreatedBy"].ToString();
                    item.CreatedOn = rdr["CreatedOn"].ObjectToDateTime();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ObjectToDateTime();
                    item.RecordStatus = rdr["RecordStatus"].ObjectToBoolean(false);
                    item.ImportBatch = rdr["ImportBatch"].ObjectToInt(0);
                    item.proUrl = rdr["proUrl"].ToString();
                    item.HomePage = rdr["HomePage"].ToString();
                });
                return item;
            }
        }
        public static SysProjectModel GetSingleSysProjectModel(string key,string value)
        {
            SysProjectModel item = null;
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "select * from SysProject where 1=1 ";
                sql += string.Format(" and {0}=@{0}",key);
                var paramMap = new Dictionary<string, object>()  {{string.Format("@{0}",key), value } };
                conn.ExecuteReader(sql, paramMap,(rdr)=>
                {
                    item = new SysProjectModel();
                    item.ID = rdr["ID"].ObjectToInt(0);
                    item.No = rdr["No"].ToString();
                    item.ProjectNo = rdr["ProjectNo"].ToString();
                    item.ProjectName = rdr["ProjectName"].ToString();
                    item.CreatedBy = rdr["CreatedBy"].ToString();
                    item.CreatedOn = rdr["CreatedOn"].ObjectToDateTime();
                    item.ModifiedBy = rdr["ModifiedBy"].ToString();
                    item.ModifiedOn = rdr["ModifiedOn"].ObjectToDateTime();
                    item.RecordStatus = rdr["RecordStatus"].ObjectToBoolean(false);
                    item.ImportBatch = rdr["ImportBatch"].ObjectToInt(0);
                    item.proUrl = rdr["proUrl"].ToString();
                    item.HomePage = rdr["HomePage"].ToString();
                });
                return item;
            }
        }
        public static int InsertSysProjectModel(SysProjectModel item)
        {
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "INSERT SysProject(No,ProjectNo,ProjectName,CreatedBy,CreatedOn,ModifiedBy,ModifiedOn,RecordStatus,ImportBatch,proUrl,HomePage) Values(@No,@ProjectNo,@ProjectName,@CreatedBy,@CreatedOn,@ModifiedBy,@ModifiedOn,@RecordStatus,@ImportBatch,@proUrl,@HomePage)"; 
                var paramMap = new Dictionary<string, object>()  {
                    { "@No", item.No },
                    { "@ProjectNo", item.ProjectNo },
                    { "@ProjectName", item.ProjectName },
                    { "@CreatedBy", item.CreatedBy },
                    { "@CreatedOn", item.CreatedOn },
                    { "@ModifiedBy", item.ModifiedBy },
                    { "@ModifiedOn", item.ModifiedOn },
                    { "@RecordStatus", item.RecordStatus },
                    { "@ImportBatch", item.ImportBatch },
                    { "@proUrl", item.proUrl },
                    { "@HomePage", item.HomePage },
                };
                return conn.ExecuteNonQuery(sql, paramMap);
            }
        }
        public static int UpdateSysProjectModel(SysProjectModel item, string whereSql)
        {
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "UPDATE SysProject set No=@No,ProjectNo=@ProjectNo,ProjectName=@ProjectName,CreatedBy=@CreatedBy,CreatedOn=@CreatedOn,ModifiedBy=@ModifiedBy,ModifiedOn=@ModifiedOn,RecordStatus=@RecordStatus,ImportBatch=@ImportBatch,proUrl=@proUrl,HomePage=@HomePage where   1 = 1 " + whereSql; 
                var paramMap = new Dictionary<string, object>()  {
                    { "@No", item.No },
                    { "@ProjectNo", item.ProjectNo },
                    { "@ProjectName", item.ProjectName },
                    { "@CreatedBy", item.CreatedBy },
                    { "@CreatedOn", item.CreatedOn },
                    { "@ModifiedBy", item.ModifiedBy },
                    { "@ModifiedOn", item.ModifiedOn },
                    { "@RecordStatus", item.RecordStatus },
                    { "@ImportBatch", item.ImportBatch },
                    { "@proUrl", item.proUrl },
                    { "@HomePage", item.HomePage },
                };
                return conn.ExecuteNonQuery(sql, paramMap);
            }
        }
        public static int DeleteSysProjectModel(string whereSql,Dictionary<string,object> paramMap)
        {
            using (var conn = DbHelper.OpenConn())
            {
                var sql = "Delete from SysProject where 1 = 1 " + whereSql;
                return conn.ExecuteNonQuery(sql, paramMap);
            }
        }
    }
}
